/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

/**
 *
 * @author user
 */
public class Product 
{
    private int ProductId;
    private String ProductName;
    private int CatalogueId;
    private double Price;
    private String Unit;
    private int Quantily;
    private String Discount;
    private int DiscountRate;
    private String Description;
    private String Images;

    /**
     * @return the ProductId
     */
    public int getProductId() {
        return ProductId;
    }

    /**
     * @param ProductId the ProductId to set
     */
    public void setProductId(int ProductId) {
        this.ProductId = ProductId;
    }

    /**
     * @return the ProductName
     */
    public String getProductName() {
        return ProductName;
    }

    /**
     * @param ProductName the ProductName to set
     */
    public void setProductName(String ProductName) {
        this.ProductName = ProductName;
    }

    /**
     * @return the CatalogueId
     */
    public int getCatalogueId() {
        return CatalogueId;
    }

    /**
     * @param CatalogueId the CatalogueId to set
     */
    public void setCatalogueId(int CatalogueId) {
        this.CatalogueId = CatalogueId;
    }

    /**
     * @return the Price
     */
    public double getPrice() {
        return Price;
    }

    /**
     * @param Price the Price to set
     */
    public void setPrice(double Price) {
        this.Price = Price;
    }

    /**
     * @return the Unit
     */
    public String getUnit() {
        return Unit;
    }

    /**
     * @param Unit the Unit to set
     */
    public void setUnit(String Unit) {
        this.Unit = Unit;
    }

    /**
     * @return the Quantily
     */
    public int getQuantily() {
        return Quantily;
    }

    /**
     * @param Quantily the Quantily to set
     */
    public void setQuantily(int Quantily) {
        this.Quantily = Quantily;
    }

    /**
     * @return the Discount
     */
    public String getDiscount() {
        return Discount;
    }

    /**
     * @param Discount the Discount to set
     */
    public void setDiscount(String Discount) {
        this.Discount = Discount;
    }
    

    /**
     * @return the Description
     */
    public String getDescription() {
        return Description;
    }

    /**
     * @param Description the Description to set
     */
    public void setDescription(String Description) {
        this.Description = Description;
    }
    public Vector<Product> Vectorproduct()
    {
        Vector<Product> productlist=new Vector<Product>();
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="select * from Product where Unit=?";
            PreparedStatement ps=con.prepareCall(query);
            ps.setString(1, this.Unit);
            ResultSet rs=ps.executeQuery();
            while(rs.next())
            {
                Product pd=new Product();
                pd.setProductId(rs.getInt("ProductId"));
                pd.setProductName(rs.getString("ProductName"));
                pd.setCatalogueId(rs.getInt("CatalogueId"));
                pd.setImages(rs.getString("Images"));
                pd.setPrice(rs.getDouble("Price"));
                pd.setUnit(rs.getString("Unit"));
                pd.setQuantily(rs.getInt("Quantily"));
                pd.setDiscount(rs.getString("Discount"));
                pd.setDiscountRate(rs.getInt("DiscountRate"));
                pd.setDescription(rs.getString("Description"));
               productlist.add(pd);
            }
        }
        catch(Exception ex)
        {
            productlist =null;
            System.out.println(ex);
        }
        return productlist;
    }
    public Product getquantityproduct()
    {
        Product productlist=new Product();
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="select Quantily from Product where ProductName=?";
            PreparedStatement ps=con.prepareCall(query);
            ps.setString(1, ProductName);
            ResultSet rs=ps.executeQuery();
            while(rs.next())
            {
               // Product pd=new Product();
                productlist.setQuantily(rs.getInt("Quantily"));
               // productlist.add(pd);
            }
        }
        catch(Exception ex)
        {
            productlist =null;
            System.out.println("sai o get"+ex);
        }
        return productlist;
    }
  public Product getdiscountrateandpriceproduct()
    {
        Product productlist=new Product();
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="select Price,DiscountRate from Product where ProductName=?";
            PreparedStatement ps=con.prepareCall(query);
            ps.setString(1, ProductName);
            ResultSet rs=ps.executeQuery();
            while(rs.next())
            {
                productlist.setPrice(rs.getDouble("Price"));
                productlist.setDiscountRate(rs.getInt("DiscountRate"));
            }
        }
        catch(Exception ex)
        {
            productlist =null;
            System.out.println("sai o get"+ex);
        }
        return productlist;
    }
 public Vector<Product> Vectorproduct1()
    {
        Vector<Product> productlist=new Vector<Product>();
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="select * from Product";
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery(query);
            while(rs.next())
            {
                Product pd=new Product();
                pd.setProductId(rs.getInt("ProductId"));
                pd.setProductName(rs.getString("ProductName"));
                pd.setCatalogueId(rs.getInt("CatalogueId"));
                pd.setImages(rs.getString("Images"));
                pd.setPrice(rs.getDouble("Price"));
                pd.setUnit(rs.getString("Unit"));
                pd.setQuantily(rs.getInt("Quantily"));
                pd.setDiscount(rs.getString("Discount"));
                pd.setDiscountRate(rs.getInt("DiscountRate"));
                pd.setDescription(rs.getString("Description"));
               productlist.add(pd);
            }
        }
        catch(Exception ex)
        {
            productlist =null;
            System.out.println(ex);
        }
        return productlist;
    }
    /**
     * @return the Images
     */
    public String getImages() {
        return Images;
    }

    /**
     * @param Images the Images to set
     */
    public void setImages(String Images) {
        this.Images = Images;
    }

    /**
     * @return the DiscountRate
     */
    public int getDiscountRate() {
        return DiscountRate;
    }

    /**
     * @param DiscountRate the DiscountRate to set
     */
    public void setDiscountRate(int DiscountRate) {
        this.DiscountRate = DiscountRate;
    }
    public boolean updateproduct()
    {
        boolean result =true;
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="update Product set Price=?, Quantily=? where ProductName like ?";
            PreparedStatement ps=con.prepareStatement(query);
           ps.setDouble(1, Price);
           ps.setInt(2, Quantily);
           ps.setString(3, ProductName);
           result=ps.executeUpdate()>0;
        }
        catch(Exception ex)
        {
            result=false;
            System.out.println("sai o update"+ex);
        }
        return result;
    }
    public boolean updateproduct11()
    {
        boolean result =true;
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="update Product set Quantily=? where ProductName like ?";
            PreparedStatement ps=con.prepareStatement(query);
           ps.setInt(1, Quantily);
           ps.setString(2, ProductName);
           result=ps.executeUpdate()>0;
        }
        catch(Exception ex)
        {
            result=false;
            System.out.println("sai o update"+ex);
        }
        return result;
    }
    
    
}
